﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;

namespace DSA
{
    public partial class _Default : System.Web.UI.Page
    {
        BigInteger[] rs = new BigInteger[2];

        protected void Button_Sign_Click(object sender, EventArgs e)
        {
            if (FileUpload_Plik.PostedFile.FileName == "")
                alert("Załaduj plik.");
            else
            {
                FileUpload_Plik.PostedFile.SaveAs(Server.MapPath(FileUpload_Plik.PostedFile.FileName));
                String inFile = Server.MapPath(FileUpload_Plik.PostedFile.FileName);

                var key = readKey("private", "public");
                rs = DigitalSignatureStandard.Sign(new FileStream(inFile, FileMode.Open), new FileStream(inFile.Insert(inFile.LastIndexOf("."), ".signed"), FileMode.Create), key);

                LabelPodpis.Text = "Podpis:";
                LabelR.Text = "R = " + rs[0].ToString();
                LabelS.Text = "S = " + rs[1].ToString();

                alert("Podpisano.");
            }

        }
    }
}
